package com.lmx.common;

import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.lmx.common.util.PropertiesFileUtil;
import com.lmx.local.SocketClient;
import com.lmx.message.SendMessageService;
import com.lmx.persistence.service.StartupInitDataService;

/**
 * 服务启动执行 Created by qin on 2016/7/7.
 */
@Component
public class StartupRunner implements CommandLineRunner {
	private Log logger = LogFactory.getLog(this.getClass());
	@Autowired
	private StartupInitDataService startupInitDataService;
	
	@Autowired
	private SendMessageService sendMessageService;
    @Autowired
    private SocketClient lsClient;
    
	@Override
	public void run(String... args) throws Exception {
        Properties properties = PropertiesFileUtil.getProperties("application.properties");
    	String serverLocalFalg=properties.getProperty("serverFlag.local");
    	//是本地服务则启动与云端的socket连接    
    	if(serverLocalFalg!=null&&!"false".equals(serverLocalFalg)){
    	    logger.debug("do socket connect");
    	    this.lsClient.connect2();
    		return;
    	}
		logger.debug(">>>>>>>>>>>>>>>服务启动执行，执行加载数据等操作  <<<<<<<<<<<<<");
		startupInitDataService.initDicttype();// 加载字典数据
		sendMessageService.serviceExecute();//消息发送进程 
	}
}
